package trade;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.VirtualLayoutManager;

import net.ck.hzq.R;

import java.util.List;

import base.BaseActivity;
import dao.MerchantTradeItem;
import trade.presenter.MerchantTradePresenter;
import trade.view.MerchantTradeView;

/**
 * by BF00233 on 2018/12/21.
 */
public class MerchantTradeActivity extends BaseActivity implements MerchantTradeView {

    private MerchantTradePresenter mPresenter;
    private MerchantTradeAdapter mTradeAdapter;

    public static void start(Context context, String month, String merchantNo) {
        Intent intent = new Intent(context, MerchantTradeActivity.class);
        intent.putExtra("month", month);
        intent.putExtra("merchantNo", merchantNo);
        context.startActivity(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_merchant_trade;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
        DelegateAdapter mDelegateAdapter = new DelegateAdapter(layoutManager);
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(mDelegateAdapter);

        mTradeAdapter = new MerchantTradeAdapter(this);
        mDelegateAdapter.addAdapter(mTradeAdapter);

        String month = getIntent().getStringExtra("month");
        String merchantNo = getIntent().getStringExtra("merchantNo");
        mPresenter = new MerchantTradePresenter(this);
        mPresenter.getTradeRecord(month, merchantNo);
        findViewById(R.id.iv_back).setOnClickListener(v -> finish());
    }

    @Override
    public void showTradeRecord(@NonNull List<MerchantTradeItem> items) {
        if (mTradeAdapter != null) {
            mTradeAdapter.setupData(items);
        }
    }

    @Override
    public BaseActivity getHostActivity() {
        return this;
    }

    @Override
    public void showProgress() {
        showProgressDialog();
    }

    @Override
    public void hideProgress() {
        dismissProgressDialog();
    }
}
